<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
session_start();
$_SESSION['TicketID'] = 1;


?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="maintenancePagesCSS.css" />
        <title></title>
        <style type='text/css'>
            <!--
            body {
                background-color: #454343;
                margin-left: 17px;
                margin-top: 0px;
                margin-right: 0px;
                margin-bottom: 0px;
            }
            -->
        </style>


        <script type='text/javascript' src='tabber.js'></script>
        <link rel='stylesheet' href='triumph.css' TYPE='text/css' MEDIA='screen'>


        <script type='text/javascript'>

            /* Optional: Temporarily hide the 'tabber' class so it does not 'flash'
           on the page as plain HTML. After tabber runs, the class is changed
           to 'tabberlive' and it will appear. */

            document.write('<style type='text/css'>.tabber{display:none;}<\/style>');
        </script>



        <style type="text/css">
            <!--
            .style3 {color: #FFFFFF}
            -->
        </style>
    </head>
    <body text="#FFFFFF">
       <?php
            $ticketID = 1;
            if($_POST['hdnID'])
           {
                include "../ProductDetails.php";
                include "../ProductDetailsDao.php";
                include "../Datasource.php";
                include "../CustomerProductDao.php";
                include "../CustomerProduct.php";
                include "../TicketDao.php";
                include "../Ticket.php";

                $conn = new Datasource("localhost","theanykey","root","");
                $tempCustomerProduct = new CustomerProduct();
                $custProduct = new CustomerProductDao();
                $tempCustomerProduct->setProductDetailsID($_POST['hdnID']);
                $tempCustomerProduct->setTicketID($ticketID);

                
                $tickID = $tempCustomerProduct->getCustomerProductID();
                $productDetID = $tempCustomerProduct->getProductDetailsID();
                echo $tickID . " " . $productDetID;
                if(!$custProduct->create($conn, $tempCustomerProduct))
                {
                    echo("The entry failed being added to the data base.");
                }
                                
            }



       ?>
        <div id="productDiv">
            <center>
                <span class="divHeader">
                    <h3>Products Used</h3>
                </span>
                <br/>
            <form action="productDiv.php" method="post" class="SelectTable">
                <div style="width: 95%; border:solid; border-width:1; background-color: #666666;"/>
                  <table align="center">
                    
                            <tr align="center" style="width:10%">
                                <td>
                                ID:
                                </td>
                                <td>
                                    <input type="text" id="pid" name="pid"/>
                                </td>
                            </tr>
                            <tr align="center" style="width:10%">
                                <td>
                                Manufacturer:
                                </td>
                                <td>
                                    <input type="text" id="Manufac" name="Manufac"/>
                                </td>
                            </tr>
                            <tr align="center" style="width:10%">
                                <td>
                                Model Number:
                                </td>
                                <td>
                                   <input type="text" id="ModelNum" name="ModelNum"/>
                                </td>
                            </tr>
                            <tr align="center" style="width:10%">
                                <td>
                                Serial Number:
                                </td>
                                <td>
                                   <input type="text"  id="SerialNum" name="SerialNum"/>
                                </td>
                            </tr>
                            <tr align="center" style="width:10%">
                                <td>
                                Company Price:
                                </td>
                                <td>
                                   <input type="text" id="CompPrice" name="CompPrice"/>
                                </td>
                            </tr>
                            <tr align="center" style="width:10%">
                                <td>
                                Customer Price:
                                </td>
                                <td>
                                   <input type="text" id="CustPrice" name="CustPrice"/>
                                </td>
                            </tr>
                            <tr align="center" style="width:10%">
                                <td>
                                Tech Notes:
                                </td>
                                <td>
                                   <input type="text" id="TechN" name="TechN"/>
                                </td>
                            </tr>
                </table>
                    <input type="button" value="Add Product" onclick="window.showModalDialog('productPopup.php', 'Add Product', 'menubar=0, toolbar=0, height=180px, width=280px');" />
                    <input type="hidden" id="hdnID" value="" name="hdnID"/>
            </center>
                <br/>
                <br/>

                    <center>
                        <h3>Previous Parts</h3>
                    </center>
                    <center>
                        <table style="width: 90%">
                            <tr>
                                <th></th>
                                <th align="center">
                                    ID
                                </th>
                                <th align="center">
                                    Manufacturer
                                </th>
                                <th align="center">
                                    Model Number
                                </th>
                                <th align="center">
                                    Serial Number
                                </th>
                                <th align="center">
                                    Company Price
                                </th>
                                <th align="center">
                                    Customer Price
                                </th>
                                <th align="center">
                                    Tech Notes
                                </th>
                            </tr>

<?php
    include "../ProductDetails.php";
    include "../ProductDetailsDao.php";
    include "../Datasource.php";
    include "../CustomerProductDao.php";
    include "../CustomerProduct.php";
    include "../TicketDao.php";
    include "../Ticket.php";
    $conn = new Datasource("localhost","theanykey","root","");
    $tempCustProd = new CustomerProduct();
    $tempCustProd->setTicketID($_SESSION['TicketID']);
    $custProdDao = new CustomerProductDao();
    $results = $custProdDao->searchMatching($conn, $tempCustProd);

    $counter = 1;
    foreach ($results as $currentRow)
    {
        $currentProdDetails = new ProductDetails();
        $currentProdDetailsDao = new ProductDetailsDao();
        $currentProdDetails = $currentProdDetailsDao->getObject($conn, $currentRow->getProductDetailsID());
        $id = $currentRow->getCustomerProductID();
        print("<tr align='center' id=custProdRow$counter name=rowID>");
         print("<td>
     <input type='button' value='Delete' onclick=\"window.open('ProductDeletePopup.php?id=$id&row=custProdRow$counter',null, 'menubar=0, toolbar=0, height=400px, width=780px')\";>
            </td>");
                    $notes = $currentProdDetails->getTechNotes();
                    $shortNotes = substr($notes, 0, 25)."...";
                      print (" <td>".$currentProdDetails->getProductID()."</td>
                        <td>".$currentProdDetails->getManufacturer()."</td>
                        <td>".$currentProdDetails->getModelNo()."</td>
                        <td>".$currentProdDetails->getSerialNo()."</td>
                        <td>".$currentProdDetails->getCompanyPrice()."</td>
                        <td>".$currentProdDetails->getCustomerPrice()."</td>
                        <td><span title='$notes'>$shortNotes</span></td>

                  </tr>");
        $counter++;
    }
    

?>

                        </table>
                    </center>
                    <span id="htmlWrite">
                    </span>
            </div>
                <input type="Submit" id="submitProduct "value="Submit"/>
        </form>
    </body>
</html>